<template>
  <div>
    <selectGoodsRadio
      :select-item="selectItem"
      @change="selectChange"
    ></selectGoodsRadio>
  </div>
</template>
  <script lang="ts">
export default {
  name: "storeDiyLinkModalGoods",
};
</script>
  <script setup lang="ts">
import { ref, getCurrentInstance, onMounted } from "vue";
import selectGoodsRadio from "@/components/select-modal/goods/radio.vue";
import { diyLinkType } from "@/types";

const {
  proxy: { $utils },
} = getCurrentInstance() as any;

const props = withDefaults(
  defineProps<{
    linkItem?: diyLinkType;
  }>(),
  {
    linkItem: () => {
      return {};
    },
  }
);

const selectItem = ref<any>({
  id: props.linkItem?.value,
  goods_name: props.linkItem?.title,
});

const selectedData = ref<diyLinkType>(props.linkItem);

const emit = defineEmits(["change"]);

const selectChange = (item: { goods_name: string; id: number | string }) => {
  selectItem.value.id = item.id;
  selectItem.value.goods_name = item.goods_name;
  selectedData.value = {
    type: "goods",
    title: item.goods_name,
    desc: "商品",
    value: item.id,
  };
  emit("change", selectedData.value);
};

onMounted(() => {});
</script>